// src\router\home.ts
import Layout from  "../layout/index.vue"
import { createRouter, createWebHashHistory } from 'vue-router'
import { RouteRecordRaw } from 'vue-router'
const routes:Array<RouteRecordRaw> = [
    {
        path: '/',
        name: '首页',
        component: Layout,
        children:[
            {
                path: '/',
                name: 'Home',
                component: () => import('../view/home/index.vue'),
                meta: {
                    title:'温州点工网络科技有限公司'
                }
            },
            {
                path: '/particulars',
                name: 'particulars',
                component: () => import('../view/particulars/index.vue'),
                meta: {
                    title:'石材详情'
                }
            },
            {
                path: '/stone',
                name: 'stone',
                component: () => import('../view/stone/index.vue'),
                meta: {
                    title:'石材列表'
                }
            }
        ]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes,
    // @ts-ignore
    scrollBehavior(to, form, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        } else {
            return { top: 0 };
        }
    },
})
router.afterEach((to) => {
    document.title = (to.meta.title || '默认标题') as  string; // 设置标题
});
export default router